package com.example.chirdrenserver.controller;


import com.example.chirdrenserver.Pojo.dto.CommentQueryDTO;
import com.example.chirdrenserver.Pojo.dto.PostCommentDTO;
import com.example.chirdrenserver.Pojo.dto.ReCommentDTO;
import com.example.chirdrenserver.Pojo.entity.Comment;
import com.example.chirdrenserver.Service.UserService.CommentService;
import com.example.chirdrenserver.Utils.Result;
import com.example.chirdrenserver.confg.SystemConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collection;

/**
 * @Author: Yu
 * @CreateTime: 2025-06-30
 * @Description:
 */
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    CommentService commentService;
    @Autowired
    SystemConfig systemConfig;
    /**
     * 回复帖子
     */
    @PostMapping("/postcomment")
    public Result postComment(@RequestBody PostCommentDTO postCommentDTO) {
       if(!(systemConfig.getSystem().get(0).getConfigKey() == 0))
       {
           return Result.error("评论未开放");
       }
        commentService.postComment(postCommentDTO);
        return Result.success();
    }

    /**
     * 回复评论
     */
    @PostMapping("/recomment")
    public Result ReComment(@RequestBody  ReCommentDTO reCommentDTO) {
        if(!(systemConfig.getSystem().get(0).getConfigKey() == 0))
        {
            return Result.error("评论未开放");
        }
        commentService.ReComment(reCommentDTO);
        return Result.success();
    }

    /**
     * 分页获取评论
     */
    @PostMapping("/list")
    public Result getComment( @RequestBody  CommentQueryDTO commentQueryDTO) {
      Collection<Comment> commentList=commentService.getComment(commentQueryDTO);
        return Result.success(commentList);
    }
}
